<template>
	<view>
		<!-- 		<web-view :src="url" id="webview" onMessage="onWebviewMessage" style="width: 100%;height: 100%;">
		</web-view> -->
		<web-view :src="url" id="webview" @message="onWebviewMessage" style="width: 100%;height: 100%;">
		</web-view>

	</view>
</template>


<script>
	export default {
		data() {
			return {
				type:0,
				url: ''
			}
		},
		onBackPress(options) {
			let pages = getCurrentPages()
			let page = pages[pages.length - 1];
			let currentPages = page.$getAppWebview()
			currentPages.close()
			return false
		},

		methods: {
			clickLeft() {
				let pages = getCurrentPages()
				let page = pages[pages.length - 1];
				let currentPages = page.$getAppWebview()
				let children = currentPages.children()
				children[0].close()
				setTimeout(() => {
					uni.navigateBack()
				}, 0)


			},
			message(event) {
				console.log('event', JSON.stringify(event.detail));
			},
			onWebviewMessage(message) {
				console.log('onWebviewMessage>>>>>', message)
				// message && my.alert({
				//   title: '收到H5消息',
				//   content: JSON.stringify(message)
				// })
				const {
					detail: {
						type,
						token,
						url,
						authFlowId
					}
				} = message
				switch (type) {
					case 'IDENTITY_ALI_FACE_AWAKE':
						// 拉起支付宝刷脸
						my.startAPVerify({
							url,
							certifyId: token,
							success: function(res) {
								console.log('success', res)
							},
							fail: function(res) {
								console.log('fail', res)
							},
							complete: function(res) {
								console.log('complete', res)
							}
						})
						break;
					case 'RN_DONE':
						// 实名认证完成
						break;
					case 'E_AUTH_FINISHED':
						// 授权认证完成 
						break;
					case 'SIGN_SUCCESS':
						// 签署成功
						// 要跳转的页面或进行其他操作
						uni.navigateBack()
						break;
					case 'SIGN_FAIL':
						// 签署失败
						break;
					case 'SEAL_EXAMINE':
						// 等待用印审批
						break;
					case 'REVOKE':
						// 签署流程撤销
						break;
					case 'REFUSE':
						// 拒签
						break;
					default:
						break;
				}
			},
			onLoad(e) {

				if(e.url){
					this.url =decodeURIComponent(e.url) 
					
				}
			
				
			
			}
		}
	}
</script>


<style scoped>

</style>